﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public void MapFBEW(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveFBEW(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryFBEW(dwData, 1);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapFBEW(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertFBEW(dwLocal);
            }
            UpdateFBEW(dwLocal);
        }
        public void InsertFBEW(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "INSERT INTO FBEW(FBWMANDANT, FBWJJJJ, FBWBELEG, FBWLFDNR, FBWART, FBWVAR, FBWFARBE, FBWGROE, FBWAUFM, FBWCHAR, FBWGNR, FBWGNRPOS, FBWVPEINH, FBWANZVP, FBWZS, FBWLO, FBWLB, FBWLP, FBWAUFBKZ, FBWAUFTYP, FBWAUFKRS, FBWAUFLFD, FBWAUFPOS, FBWAFOLGE, FBWTEILNR, FBWKSTKRS, FBWKST, FBWMNRKRS, FBWMLFDNR, FBWMPOS, FBWSCHICHT, FBWAPOS, FBWSETPOS, FBWBUDGET, FBWFCODE, FBWBS, FBWWERTDAT, FBWME, FBWWERT, FBWWEKORR, FBWBUCHBEN, FBWBUCHDAT, FBWBUCHUHR, FBWFC, FBWINVBLG, FBWCHARL, FBWCHARLZUS, FBWSTORKZ, FBWKONDAT, FBWMATABR, FBWDISPOKZ, FBWSAPKZ, FBWACTION, FBWFILLER)"
                + " VALUES (:FBWMANDANT, :FBWJJJJ, :FBWBELEG, :FBWLFDNR, 'B08F3BS002          ', '  ', 'L         ', '0120   ', '  ', '0000306', '0000', '0000', '   ', '0000', '1A', '01', '01', '01      ', 'N', 'B', 'FP', '000166', '006', '000', '0000', '  ', '0000', '  ', '0000', '00', '0', '0000', '0000', '        ', '   ', '11', 20131223, 58, 0, '  ', 'LUYJ    ', 20131223, 9270247, 'FB04    ', 0, '               ', '               ', ' ', 0, ' ', ' ', ' ', '  ', '                                                                             ')";
            or1.Parameters.Add("FBWMANDANT", OracleType.NVarChar).Value = dwData["FBWMANDANT"].ToString();
            or1.Parameters.Add("FBWJJJJ", OracleType.NVarChar).Value = dwData["FBWJJJJ"].ToString();
            or1.Parameters.Add("FBWBELEG", OracleType.NVarChar).Value = dwData["FBWBELEG"].ToString();
            or1.Parameters.Add("FBWLFDNR", OracleType.NVarChar).Value = dwData["FBWLFDNR"].ToString();
            Connect2Proxy(or1);
        }
        public DataSet QueryFBEW(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM FBEW WHERE  ROWNUM<2 ";
                    break;
                case 1://FBWJJJJ	FBWBELEG	FBWLFDNR

                    or1.CommandText = "SELECT * FROM FBEW"
                        + " WHERE FBWMANDANT=:FBWMANDANT AND FBWJJJJ=:FBWJJJJ AND FBWBELEG=:FBWBELEG AND FBWLFDNR=:FBWLFDNR  ";
                    or1.Parameters.Add("FBWMANDANT", OracleType.NVarChar).Value = dwData["FBWMANDANT"].ToString();
                    or1.Parameters.Add("FBWJJJJ", OracleType.NVarChar).Value = dwData["FBWJJJJ"].ToString();
                    or1.Parameters.Add("FBWBELEG", OracleType.NVarChar).Value = dwData["FBWBELEG"].ToString();
                    or1.Parameters.Add("FBWLFDNR", OracleType.NVarChar).Value = dwData["FBWLFDNR"].ToString();

                    break;
                case 2://FBWJJJJ	FBWBELEG	FBWLFDNR

                    or1.CommandText = "SELECT * FROM FBEW"
                        + " WHERE FBWMANDANT=:FBWMANDANT AND FBWAUFKRS=:FBWAUFKRS AND FBWAUFLFD=:FBWAUFLFD AND FBWAUFPOS=:FBWAUFPOS  "
                        + " AND FBWART=:FBWART AND FBWFARBE=:FBWFARBE AND FBWGROE=:FBWGROE ";
                    or1.Parameters.Add("FBWMANDANT", OracleType.NVarChar).Value = dwData["FBWMANDANT"].ToString();
                    or1.Parameters.Add("FBWAUFKRS", OracleType.NVarChar).Value = dwData["FBWAUFKRS"].ToString();
                    or1.Parameters.Add("FBWAUFLFD", OracleType.NVarChar).Value = dwData["FBWAUFLFD"].ToString();
                    or1.Parameters.Add("FBWAUFPOS", OracleType.NVarChar).Value = dwData["FBWAUFPOS"].ToString();
                    or1.Parameters.Add("FBWART", OracleType.NVarChar).Value = dwData["FBWART"].ToString();
                    or1.Parameters.Add("FBWFARBE", OracleType.NVarChar).Value = dwData["FBWFARBE"].ToString();
                    or1.Parameters.Add("FBWGROE", OracleType.NVarChar).Value = dwData["FBWGROE"].ToString();
                    break;
                case 99:
                    or1.CommandText = "SELECT FBWAUFKRS,FBWAUFLFD,FBWAUFPOS,FBWART,FBWVAR,FBWFARBE,FBWGROE,FBWBS,SUM(FBWME) AS FBWME"
                    + " FROM FBEW"
                    + " WHERE FBWMANDANT=:FBWMANDANT AND FBWAUFTYP='V' AND FBWAUFKRS=:FBWAUFKRS AND FBWAUFLFD=:FBWAUFLFD  "
                    + " GROUP BY FBWAUFTYP,FBWAUFKRS,FBWAUFLFD,FBWAUFPOS,FBWART,FBWVAR,FBWFARBE,FBWGROE,FBWBS";
                    or1.Parameters.Add("FBWMANDANT", OracleType.NVarChar).Value = dwData["FBWMANDANT"].ToString();
                    or1.Parameters.Add("FBWAUFKRS", OracleType.NVarChar).Value = dwData["FBWAUFKRS"].ToString();
                    or1.Parameters.Add("FBWAUFLFD", OracleType.NVarChar).Value = dwData["FBWAUFLFD"].ToString();
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "FBEW";
            Return = Result;
            return Return;
        }
        public void UpdateFBEW(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "UPDATE FBEW SET "
+ "FBWMANDANT=:FBWMANDANT,"
+ "FBWJJJJ=:FBWJJJJ,"
+ "FBWBELEG=:FBWBELEG,"
+ "FBWLFDNR=:FBWLFDNR,"
+ "FBWART=:FBWART,"
+ "FBWVAR=:FBWVAR,"
+ "FBWFARBE=:FBWFARBE,"
+ "FBWGROE=:FBWGROE,"
+ "FBWAUFM=:FBWAUFM,"
+ "FBWCHAR=:FBWCHAR,"
+ "FBWGNR=:FBWGNR,"
+ "FBWGNRPOS=:FBWGNRPOS,"
+ "FBWVPEINH=:FBWVPEINH,"
+ "FBWANZVP=:FBWANZVP,"
+ "FBWZS=:FBWZS,"
+ "FBWLO=:FBWLO,"
+ "FBWLB=:FBWLB,"
+ "FBWLP=:FBWLP,"
+ "FBWAUFBKZ=:FBWAUFBKZ,"
+ "FBWAUFTYP=:FBWAUFTYP,"
+ "FBWAUFKRS=:FBWAUFKRS,"
+ "FBWAUFLFD=:FBWAUFLFD,"
+ "FBWAUFPOS=:FBWAUFPOS,"
+ "FBWAFOLGE=:FBWAFOLGE,"
+ "FBWTEILNR=:FBWTEILNR,"
+ "FBWKSTKRS=:FBWKSTKRS,"
+ "FBWKST=:FBWKST,"
+ "FBWMNRKRS=:FBWMNRKRS,"
+ "FBWMLFDNR=:FBWMLFDNR,"
+ "FBWMPOS=:FBWMPOS,"
+ "FBWSCHICHT=:FBWSCHICHT,"
+ "FBWAPOS=:FBWAPOS,"
+ "FBWSETPOS=:FBWSETPOS,"
+ "FBWBUDGET=:FBWBUDGET,"
+ "FBWFCODE=:FBWFCODE,"
+ "FBWBS=:FBWBS,"
+ "FBWWERTDAT=:FBWWERTDAT,"
+ "FBWME=:FBWME,"
+ "FBWWERT=:FBWWERT,"
+ "FBWWEKORR=:FBWWEKORR,"
+ "FBWBUCHBEN=:FBWBUCHBEN,"
+ "FBWBUCHDAT=:FBWBUCHDAT,"
+ "FBWBUCHUHR=:FBWBUCHUHR,"
+ "FBWFC=:FBWFC,"
+ "FBWINVBLG=:FBWINVBLG,"
+ "FBWCHARL=:FBWCHARL,"
+ "FBWCHARLZUS=:FBWCHARLZUS,"
+ "FBWSTORKZ=:FBWSTORKZ,"
+ "FBWKONDAT=:FBWKONDAT,"
+ "FBWMATABR=:FBWMATABR,"
+ "FBWDISPOKZ=:FBWDISPOKZ,"
+ "FBWSAPKZ=:FBWSAPKZ,"
+ "FBWACTION=:FBWACTION,"
+ "FBWFILLER=:FBWFILLER "
+ " WHERE FBWMANDANT=:FBWMANDANT AND FBWJJJJ=:FBWJJJJ AND FBWBELEG=:FBWBELEG AND FBWLFDNR=:FBWLFDNR  ";
                    or1.Parameters.Add("FBWMANDANT", OracleType.NVarChar).Value = dwData["FBWMANDANT"].ToString();
                    or1.Parameters.Add("FBWJJJJ", OracleType.NVarChar).Value = dwData["FBWJJJJ"].ToString();
                    or1.Parameters.Add("FBWBELEG", OracleType.NVarChar).Value = dwData["FBWBELEG"].ToString();
                    or1.Parameters.Add("FBWLFDNR", OracleType.NVarChar).Value = dwData["FBWLFDNR"].ToString();
                    or1.Parameters.Add("FBWART", OracleType.NVarChar).Value = dwData["FBWART"].ToString();
                    or1.Parameters.Add("FBWVAR", OracleType.NVarChar).Value = dwData["FBWVAR"].ToString();
                    or1.Parameters.Add("FBWFARBE", OracleType.NVarChar).Value = dwData["FBWFARBE"].ToString();
                    or1.Parameters.Add("FBWGROE", OracleType.NVarChar).Value = dwData["FBWGROE"].ToString();
                    or1.Parameters.Add("FBWAUFM", OracleType.NVarChar).Value = dwData["FBWAUFM"].ToString();
                    or1.Parameters.Add("FBWCHAR", OracleType.NVarChar).Value = dwData["FBWCHAR"].ToString();
                    or1.Parameters.Add("FBWGNR", OracleType.NVarChar).Value = dwData["FBWGNR"].ToString();
                    or1.Parameters.Add("FBWGNRPOS", OracleType.NVarChar).Value = dwData["FBWGNRPOS"].ToString();
                    or1.Parameters.Add("FBWVPEINH", OracleType.NVarChar).Value = dwData["FBWVPEINH"].ToString();
                    or1.Parameters.Add("FBWANZVP", OracleType.NVarChar).Value = dwData["FBWANZVP"].ToString();
                    or1.Parameters.Add("FBWZS", OracleType.NVarChar).Value = dwData["FBWZS"].ToString();
                    or1.Parameters.Add("FBWLO", OracleType.NVarChar).Value = dwData["FBWLO"].ToString();
                    or1.Parameters.Add("FBWLB", OracleType.NVarChar).Value = dwData["FBWLB"].ToString();
                    or1.Parameters.Add("FBWLP", OracleType.NVarChar).Value = dwData["FBWLP"].ToString();
                    or1.Parameters.Add("FBWAUFBKZ", OracleType.NVarChar).Value = dwData["FBWAUFBKZ"].ToString();
                    or1.Parameters.Add("FBWAUFTYP", OracleType.NVarChar).Value = dwData["FBWAUFTYP"].ToString();
                    or1.Parameters.Add("FBWAUFKRS", OracleType.NVarChar).Value = dwData["FBWAUFKRS"].ToString();
                    or1.Parameters.Add("FBWAUFLFD", OracleType.NVarChar).Value = dwData["FBWAUFLFD"].ToString();
                    or1.Parameters.Add("FBWAUFPOS", OracleType.NVarChar).Value = dwData["FBWAUFPOS"].ToString();
                    or1.Parameters.Add("FBWAFOLGE", OracleType.NVarChar).Value = dwData["FBWAFOLGE"].ToString();
                    or1.Parameters.Add("FBWTEILNR", OracleType.NVarChar).Value = dwData["FBWTEILNR"].ToString();
                    or1.Parameters.Add("FBWKSTKRS", OracleType.NVarChar).Value = dwData["FBWKSTKRS"].ToString();
                    or1.Parameters.Add("FBWKST", OracleType.NVarChar).Value = dwData["FBWKST"].ToString();
                    or1.Parameters.Add("FBWMNRKRS", OracleType.NVarChar).Value = dwData["FBWMNRKRS"].ToString();
                    or1.Parameters.Add("FBWMLFDNR", OracleType.NVarChar).Value = dwData["FBWMLFDNR"].ToString();
                    or1.Parameters.Add("FBWMPOS", OracleType.NVarChar).Value = dwData["FBWMPOS"].ToString();
                    or1.Parameters.Add("FBWSCHICHT", OracleType.NVarChar).Value = dwData["FBWSCHICHT"].ToString();
                    or1.Parameters.Add("FBWAPOS", OracleType.NVarChar).Value = dwData["FBWAPOS"].ToString();
                    or1.Parameters.Add("FBWSETPOS", OracleType.NVarChar).Value = dwData["FBWSETPOS"].ToString();
                    or1.Parameters.Add("FBWBUDGET", OracleType.NVarChar).Value = dwData["FBWBUDGET"].ToString();
                    or1.Parameters.Add("FBWFCODE", OracleType.NVarChar).Value = dwData["FBWFCODE"].ToString();
                    or1.Parameters.Add("FBWBS", OracleType.NVarChar).Value = dwData["FBWBS"].ToString();
                    or1.Parameters.Add("FBWWERTDAT", OracleType.NVarChar).Value = dwData["FBWWERTDAT"].ToString();
                    or1.Parameters.Add("FBWME", OracleType.NVarChar).Value = dwData["FBWME"].ToString();
                    or1.Parameters.Add("FBWWERT", OracleType.NVarChar).Value = dwData["FBWWERT"].ToString();
                    or1.Parameters.Add("FBWWEKORR", OracleType.NVarChar).Value = dwData["FBWWEKORR"].ToString();
                    or1.Parameters.Add("FBWBUCHBEN", OracleType.NVarChar).Value = dwData["FBWBUCHBEN"].ToString();
                    or1.Parameters.Add("FBWBUCHDAT", OracleType.NVarChar).Value = dwData["FBWBUCHDAT"].ToString();
                    or1.Parameters.Add("FBWBUCHUHR", OracleType.NVarChar).Value = dwData["FBWBUCHUHR"].ToString();
                    or1.Parameters.Add("FBWFC", OracleType.NVarChar).Value = dwData["FBWFC"].ToString();
                    or1.Parameters.Add("FBWINVBLG", OracleType.NVarChar).Value = dwData["FBWINVBLG"].ToString();
                    or1.Parameters.Add("FBWCHARL", OracleType.NVarChar).Value = dwData["FBWCHARL"].ToString();
                    or1.Parameters.Add("FBWCHARLZUS", OracleType.NVarChar).Value = dwData["FBWCHARLZUS"].ToString();
                    or1.Parameters.Add("FBWSTORKZ", OracleType.NVarChar).Value = dwData["FBWSTORKZ"].ToString();
                    or1.Parameters.Add("FBWKONDAT", OracleType.NVarChar).Value = dwData["FBWKONDAT"].ToString();
                    or1.Parameters.Add("FBWMATABR", OracleType.NVarChar).Value = dwData["FBWMATABR"].ToString();
                    or1.Parameters.Add("FBWDISPOKZ", OracleType.NVarChar).Value = dwData["FBWDISPOKZ"].ToString();
                    or1.Parameters.Add("FBWSAPKZ", OracleType.NVarChar).Value = dwData["FBWSAPKZ"].ToString();
                    or1.Parameters.Add("FBWACTION", OracleType.NVarChar).Value = dwData["FBWACTION"].ToString();
                    or1.Parameters.Add("FBWFILLER", OracleType.NVarChar).Value = dwData["FBWFILLER"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        }
    }
}
